package com.cb.domain.service.excelWork.Impl;

import java.util.HashMap;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.dom4j.Element;
import org.springframework.stereotype.Service;

import com.cb.domain.model.order.Policy;
import com.cb.domain.service.excelWork.AbrExcelWorker;
import com.cb.domain.service.excelWork.EXL_TYPE;
/**
 * 特价政策xls转换bean
 * @author Administrator
 *
 */
@Service
public class LowPriceWorker extends AbrExcelWorker {

	@Override
	protected void createXmlStr(int rowIndex, Element root) {
		// TODO Auto-generated method stub
		Element policy=root.addElement("Policy");
		policy.addAttribute("flightcode", getExlContent(EXL_TYPE.AIRCOMPANY, rowIndex));
		policy.addAttribute("policyCode", getExlContent(EXL_TYPE.POLICYNO, rowIndex));
		policy.addAttribute("dpt", getExlContent(EXL_TYPE.DEPCITY, rowIndex));
		policy.addAttribute("arr", getExlContent(EXL_TYPE.ARRCITY, rowIndex));
		policy.addAttribute("flightNumLimit", getExlContent(EXL_TYPE.SEGLIMITED, rowIndex));
		policy.addAttribute("flightcondition", getExlContent(EXL_TYPE.FLIGHTNO, rowIndex));
		policy.addAttribute("daycondition", getExlContent(EXL_TYPE.TIMELIMITED, rowIndex));
		policy.addAttribute("cabin", getExlContent(EXL_TYPE.SEGCLASS, rowIndex));
		policy.addAttribute("discountType", getExlContent(EXL_TYPE.TICKETPRICETYPE, rowIndex));
		policy.addAttribute("discountValue", getExlContent(EXL_TYPE.PRICEORAGIO, rowIndex));
		policy.addAttribute("returnpoint", getExlContent(EXL_TYPE.COMMISSIONRATE, rowIndex));
		policy.addAttribute("returnprice", getExlContent(EXL_TYPE.REMAINPRICE, rowIndex));
		policy.addAttribute("startdate_ticket", getExlContent(EXL_TYPE.SALEBEGINDATE, rowIndex));
		policy.addAttribute("enfdate_ticket", getExlContent(EXL_TYPE.SALEENDDATE, rowIndex));
		policy.addAttribute("startdate", getExlContent(EXL_TYPE.TRAVELBEGINDATE, rowIndex));
		policy.addAttribute("enddate", getExlContent(EXL_TYPE.TRAVELENDATE, rowIndex));
		policy.addAttribute("beforeValidDay", getExlContent(EXL_TYPE.EARLYTIME, rowIndex));
		policy.addAttribute("backnote", getExlContent(EXL_TYPE.ER, rowIndex));
		policy.addAttribute("cabinnote", getExlContent(EXL_TYPE.CLASSREMARK, rowIndex));
		policy.addAttribute("autoTicket", getExlContent(EXL_TYPE.ISAUTOTICKET, rowIndex));
		policy.addAttribute("costtype", getExlContent(EXL_TYPE.PRICETYPE, rowIndex));
		policy.addAttribute("costPrice", getExlContent(EXL_TYPE.BASEPRICE, rowIndex));
		policy.addAttribute("proxyPrice", getExlContent(EXL_TYPE.ZVALUE, rowIndex));
		policy.addAttribute("backPrice", getExlContent(EXL_TYPE.COMMISSION, rowIndex));
		policy.addAttribute("policySource","");
		policy.addAttribute("bridgeOffice",getExlContent(EXL_TYPE.BRIDGEOFFICE, rowIndex));
		policy.addAttribute("isSingleTrip",getExlContent(EXL_TYPE.ISSINGLETRIP, rowIndex));
	}

	@Override
	protected void initMap() {
		// TODO Auto-generated method stub
		xmlMap=new HashMap<EXL_TYPE, Integer>();
		xmlMap.put(EXL_TYPE.AIRCOMPANY, 0);
		xmlMap.put(EXL_TYPE.POLICYNO, 1);
		xmlMap.put(EXL_TYPE.DEPCITY, 2);
		xmlMap.put(EXL_TYPE.ARRCITY, 3);
		xmlMap.put(EXL_TYPE.SEGLIMITED, 4);
		xmlMap.put(EXL_TYPE.FLIGHTNO, 5);
		xmlMap.put(EXL_TYPE.TIMELIMITED, 6);
		xmlMap.put(EXL_TYPE.SEGCLASS, 7);
		xmlMap.put(EXL_TYPE.TICKETPRICETYPE,8);
		xmlMap.put(EXL_TYPE.PRICEORAGIO, 9);
		xmlMap.put(EXL_TYPE.COMMISSIONRATE, 10);
		xmlMap.put(EXL_TYPE.REMAINPRICE, 11);
		xmlMap.put(EXL_TYPE.SALEBEGINDATE, 12);
		xmlMap.put(EXL_TYPE.SALEENDDATE, 13);
		xmlMap.put(EXL_TYPE.TRAVELBEGINDATE, 14);
		xmlMap.put(EXL_TYPE.TRAVELENDATE, 15);
		xmlMap.put(EXL_TYPE.EARLYTIME, 16);
		xmlMap.put(EXL_TYPE.ER, 17);
		xmlMap.put(EXL_TYPE.CLASSREMARK, 18);
		xmlMap.put(EXL_TYPE.ISAUTOTICKET, 19);
		xmlMap.put(EXL_TYPE.PRICETYPE, 20);
		xmlMap.put(EXL_TYPE.BASEPRICE, 21);
		xmlMap.put(EXL_TYPE.ZVALUE, 22);
		xmlMap.put(EXL_TYPE.COMMISSION, 23);
		xmlMap.put(EXL_TYPE.BRIDGEOFFICE, 24);
		xmlMap.put(EXL_TYPE.ISSINGLETRIP, 25);
	}

	@Override
	protected Policy setPolicyInfo(Element policyItem) throws Exception {
		// TODO Auto-generated method stub
		Policy policy=new Policy();
		policy.setPata(policyItem.attributeValue("pata"));
		policy.setCanPay(policyItem.attributeValue("canPay"));
		if(StringUtils.isNotEmpty(policyItem.attributeValue("returnpoint"))){
			policy.setReturnPoint(Double.valueOf(policyItem.attributeValue("returnpoint")));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("returnprice"))){
			policy.setReturnPrice(new Long(policyItem.attributeValue("returnprice")));
		}
		policy.setAutoTicket(policyItem.attributeValue("autoTicket"));
		policy.setShared(policyItem.attributeValue("shared"));
		policy.setFlightCode(policyItem.attributeValue("flightcode"));
		policy.setPolicyCode(policyItem.attributeValue("policyCode"));
		policy.setDpt(policyItem.attributeValue("dpt"));
		policy.setArr(policyItem.attributeValue("arr"));
		policy.setFlightNumLimit(policyItem.attributeValue("flightNumLimit"));
		policy.setFlightCondition(policyItem.attributeValue("flightcondition"));
		policy.setDaycondition(policyItem.attributeValue("daycondition"));
		policy.setCabin(policyItem.attributeValue("cabin"));
		policy.setDiscountType(policyItem.attributeValue("discountType"));
		if(StringUtils.isNotEmpty(policyItem.attributeValue("discountValue"))){
			policy.setDiscountValue(Double.valueOf(policyItem.attributeValue("discountValue")));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("returnpoint"))){
			policy.setReturnPoint(Double.valueOf(policyItem.attributeValue("returnpoint")));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("returnprice"))){
			policy.setReturnPrice(new Long(policyItem.attributeValue("returnprice")));
		}
		
		if(StringUtils.isNotEmpty(policyItem.attributeValue("startdate_ticket"))){
			policy.setStartdateTicket(DateUtils.parseDate(policyItem.attributeValue("startdate_ticket"), new String[]{"yyyy-MM-dd","yyyy/MM/dd"}));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("enfdate_ticket"))){
			policy.setEnfdateTicket(DateUtils.parseDate(policyItem.attributeValue("enfdate_ticket"), new String[]{"yyyy-MM-dd","yyyy/MM/dd"}));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("startdate"))){
			policy.setStartDate(DateUtils.parseDate(policyItem.attributeValue("startdate"), new String[]{"yyyy-MM-dd","yyyy/MM/dd"}));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("enddate"))){
			policy.setEndDate(DateUtils.parseDate(policyItem.attributeValue("enddate"), new String[]{"yyyy-MM-dd","yyyy/MM/dd"}));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("beforeValidDay"))){
			policy.setBeforeValidDay(new Long(policyItem.attributeValue("beforeValidDay")));
		}
		policy.setBackNote(policyItem.attributeValue("backnote"));
		policy.setCabinNote(policyItem.attributeValue("cabinnote"));
		policy.setCostType(policyItem.attributeValue("costtype"));
		if(StringUtils.isNotEmpty(policyItem.attributeValue("costPrice"))){
			policy.setCostPrice(new Long(policyItem.attributeValue("costPrice")));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("proxyPrice"))){
			policy.setProxyPrice(Double.valueOf(policyItem.attributeValue("proxyPrice")));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("backPrice"))){
			policy.setBackPrice(Double.valueOf(policyItem.attributeValue("backPrice")));
		}
		if(StringUtils.isNotEmpty(policyItem.attributeValue("bridgeOffice"))){
			policy.setBridgeOffice(policyItem.attributeValue("bridgeOffice"));
		}
		
		if(StringUtils.isNotEmpty(policyItem.attributeValue("isSingleTrip"))){
			policy.setIsSingleTrip(policyItem.attributeValue("isSingleTrip"));
		}
		return policy;
	}

}
